from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-08 14:02:36.712881
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 08, Jun, 2022
Time: 14:02:44
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.5117
Nobs: 681.000 HQIC: -49.8781
Log likelihood: 8455.61 FPE: 1.72873e-22
AIC: -50.1095 Det(Omega_mle): 1.51617e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.307726 0.059176 5.200 0.000
L1.Burgenland 0.105411 0.038339 2.749 0.006
L1.Kärnten -0.109115 0.020204 -5.401 0.000
L1.Niederösterreich 0.200020 0.079939 2.502 0.012
L1.Oberösterreich 0.120217 0.078860 1.524 0.127
L1.Salzburg 0.255066 0.040871 6.241 0.000
L1.Steiermark 0.047636 0.053555 0.889 0.374
L1.Tirol 0.105595 0.043343 2.436 0.015
L1.Vorarlberg -0.061797 0.038117 -1.621 0.105
L1.Wien 0.033818 0.069966 0.483 0.629
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.041489 0.125314 0.331 0.741
L1.Burgenland -0.033610 0.081187 -0.414 0.679
L1.Kärnten 0.039917 0.042785 0.933 0.351
L1.Niederösterreich -0.182104 0.169282 -1.076 0.282
L1.Oberösterreich 0.440293 0.166996 2.637 0.008
L1.Salzburg 0.285282 0.086549 3.296 0.001
L1.Steiermark 0.108203 0.113409 0.954 0.340
L1.Tirol 0.315508 0.091784 3.438 0.001
L1.Vorarlberg 0.026321 0.080718 0.326 0.744
L1.Wien -0.033750 0.148164 -0.228 0.820
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186864 0.030380 6.151 0.000
L1.Burgenland 0.089186 0.019682 4.531 0.000
L1.Kärnten -0.007699 0.010372 -0.742 0.458
L1.Niederösterreich 0.256651 0.041039 6.254 0.000
L1.Oberösterreich 0.147455 0.040485 3.642 0.000
L1.Salzburg 0.044815 0.020982 2.136 0.033
L1.Steiermark 0.025755 0.027494 0.937 0.349
L1.Tirol 0.086911 0.022251 3.906 0.000
L1.Vorarlberg 0.053563 0.019568 2.737 0.006
L1.Wien 0.117458 0.035919 3.270 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110401 0.030589 3.609 0.000
L1.Burgenland 0.043613 0.019818 2.201 0.028
L1.Kärnten -0.013815 0.010444 -1.323 0.186
L1.Niederösterreich 0.185786 0.041322 4.496 0.000
L1.Oberösterreich 0.317995 0.040764 7.801 0.000
L1.Salzburg 0.103011 0.021127 4.876 0.000
L1.Steiermark 0.109993 0.027684 3.973 0.000
L1.Tirol 0.099111 0.022405 4.424 0.000
L1.Vorarlberg 0.062826 0.019703 3.189 0.001
L1.Wien -0.019895 0.036167 -0.550 0.582
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.122134 0.056489 2.162 0.031
L1.Burgenland -0.048070 0.036598 -1.313 0.189
L1.Kärnten -0.045906 0.019287 -2.380 0.017
L1.Niederösterreich 0.146452 0.076309 1.919 0.055
L1.Oberösterreich 0.153050 0.075279 2.033 0.042
L1.Salzburg 0.282094 0.039015 7.230 0.000
L1.Steiermark 0.053985 0.051123 1.056 0.291
L1.Tirol 0.166270 0.041375 4.019 0.000
L1.Vorarlberg 0.094712 0.036386 2.603 0.009
L1.Wien 0.077707 0.066790 1.163 0.245
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061675 0.044592 1.383 0.167
L1.Burgenland 0.030444 0.028890 1.054 0.292
L1.Kärnten 0.051580 0.015225 3.388 0.001
L1.Niederösterreich 0.205745 0.060238 3.416 0.001
L1.Oberösterreich 0.309954 0.059425 5.216 0.000
L1.Salzburg 0.042523 0.030798 1.381 0.167
L1.Steiermark 0.009869 0.040356 0.245 0.807
L1.Tirol 0.133556 0.032661 4.089 0.000
L1.Vorarlberg 0.067726 0.028723 2.358 0.018
L1.Wien 0.087363 0.052723 1.657 0.098
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170992 0.053553 3.193 0.001
L1.Burgenland 0.002307 0.034696 0.067 0.947
L1.Kärnten -0.064376 0.018284 -3.521 0.000
L1.Niederösterreich -0.089487 0.072343 -1.237 0.216
L1.Oberösterreich 0.195474 0.071366 2.739 0.006
L1.Salzburg 0.055733 0.036987 1.507 0.132
L1.Steiermark 0.239662 0.048466 4.945 0.000
L1.Tirol 0.502108 0.039224 12.801 0.000
L1.Vorarlberg 0.058085 0.034495 1.684 0.092
L1.Wien -0.068007 0.063318 -1.074 0.283
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.154767 0.060314 2.566 0.010
L1.Burgenland -0.006000 0.039076 -0.154 0.878
L1.Kärnten 0.061840 0.020593 3.003 0.003
L1.Niederösterreich 0.193646 0.081476 2.377 0.017
L1.Oberösterreich -0.074559 0.080375 -0.928 0.354
L1.Salzburg 0.209122 0.041656 5.020 0.000
L1.Steiermark 0.133780 0.054584 2.451 0.014
L1.Tirol 0.071361 0.044176 1.615 0.106
L1.Vorarlberg 0.137976 0.038850 3.552 0.000
L1.Wien 0.120526 0.071311 1.690 0.091
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.374677 0.035060 10.687 0.000
L1.Burgenland -0.001386 0.022714 -0.061 0.951
L1.Kärnten -0.022256 0.011970 -1.859 0.063
L1.Niederösterreich 0.214698 0.047361 4.533 0.000
L1.Oberösterreich 0.221292 0.046721 4.736 0.000
L1.Salzburg 0.041230 0.024214 1.703 0.089
L1.Steiermark -0.015822 0.031729 -0.499 0.618
L1.Tirol 0.098031 0.025679 3.818 0.000
L1.Vorarlberg 0.056941 0.022583 2.521 0.012
L1.Wien 0.034415 0.041452 0.830 0.406
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037525 0.122843 0.182810 0.147207 0.105849 0.089610 0.045630 0.211941
Kärnten 0.037525 1.000000 -0.018210 0.134341 0.053110 0.092329 0.439090 -0.058100 0.094302
Niederösterreich 0.122843 -0.018210 1.000000 0.329127 0.132244 0.287423 0.078923 0.161084 0.307944
Oberösterreich 0.182810 0.134341 0.329127 1.000000 0.223530 0.314541 0.171568 0.156384 0.258386
Salzburg 0.147207 0.053110 0.132244 0.223530 1.000000 0.133031 0.106716 0.126287 0.131729
Steiermark 0.105849 0.092329 0.287423 0.314541 0.133031 1.000000 0.143224 0.120978 0.058288
Tirol 0.089610 0.439090 0.078923 0.171568 0.106716 0.143224 1.000000 0.092275 0.148923
Vorarlberg 0.045630 -0.058100 0.161084 0.156384 0.126287 0.120978 0.092275 1.000000 0.009685
Wien 0.211941 0.094302 0.307944 0.258386 0.131729 0.058288 0.148923 0.009685 1.000000